package Bluehostto;

use WWW::Mechanize;
use HTTP::Cookies;

sub upload
{
    my $local_file = shift;
	my $hoster_config = shift;

    my $mech = WWW::Mechanize->new();

    my $cookie_jar = HTTP::Cookies->new(
            file => $::spreader_cookie_dir."bluehostto.dat",
            autosave => 1,
        );

    $mech->cookie_jar($cookie_jar);

    my $textbox_content =  "ftp://".$::spreader_ftp_user.":".$::spreader_ftp_pwd."\@".$::spreader_ftp_ip.$::spreader_ftp_path.$local_file."\n";

    $mech->get("http://bluehost.to/index.php");

    if($mech->content =~ /loginname/)
    {
        $mech->form_number(1);
        $mech->field("loginname" => $hoster_config->{'username'});
        $mech->field("loginpass" => $hoster_config->{'password'});
        $mech->click("gobutton");
    }

    $mech->get("http://bluehost.to/remote.php");

    $mech->form_number(2);
    $mech->field("remoteupload" => "do");
    $mech->field("remotelinks" => $textbox_content);
    $mech->submit();

    if($mech->content =~ m!(http://bluehost.to/dl=.*?)\'!)
    {
        return $1;
    }
    else
    {
        return "FEHLER BEIM UPLOAD DER DATEI ".$local_file;
    }
}
1;